<?php
(!defined('IN_SYSTEM') || !defined('ADMIN_PRE')) && exit('Access Denied!');
$f = isset($_REQUEST['f'])?$_REQUEST['f']:'index';
$m = new CarModule;
$m->$f();
class CarModule
{
	function index() {
		global $_G;
		$kw=getGP('keyword','G');
		
		if($kw){
			$where =" AND a.title LIKE '%$kw%' OR a.contact  LIKE '%$kw%' OR a.phone  LIKE '%$kw%'  ";
		}
		$order=" ORDER BY a.id DESC ";
		$query=$_G['db']->page_query("SELECT a.*,c.catename,u.username FROM".table('car_cars')."a LEFT JOIN".table("category")."c ON a.bid=c.cid  LEFT JOIN".table("users")."u ON a.uid=u.uid WHERE 1 $where $order",10);
		while($rs=$_G['db']->fetch_array($query)){
			$datas[]=$rs;
		}
		$num=$_G['db']->result("SELECT count(id) FROM".table('car_cars')."a WHERE 1 $where ");
		$page=pager($num,10);
		include admintemplate('car/index');
	}
	function qiugou() {
		global $_G;
		$kw=getGP('keyword','G');
		if($kw){
			$where =" AND  a.title LIKE '%$kw%' OR a.contact  LIKE '%$kw%' OR a.phone  LIKE '%$kw%'  ";
		}
		$order=" ORDER BY a.id DESC ";
		$query=$_G['db']->page_query("SELECT a.*,c.catename,u.username FROM".table('car_qiugou')."a LEFT JOIN".table("category")."c ON a.bid=c.cid  LEFT JOIN".table("users")."u ON a.uid=u.uid WHERE 1 $where $order",10);
		while($rs=$_G['db']->fetch_array($query)){
			$datas[]=$rs;
		}
		$num=$_G['db']->result("SELECT count(id) FROM".table('car_qiugou')."a WHERE 1 $where ");
		$page=pager($num,10);
		include admintemplate('car/qiugou');
	}
	function pinggu() {
		global $_G;
		$kw=getGP('keyword','G');
		if($kw){
			$where =" AND  a.description LIKE '%$kw%' OR a.contact  LIKE '%$kw%' OR a.phone  LIKE '%$kw%'  ";
		}
		$order=" ORDER BY a.id DESC ";
		$query=$_G['db']->page_query("SELECT a.*,u.username FROM".table('car_pinggu')."a LEFT JOIN".table("users")."u ON a.uid=u.uid WHERE 1 $where $order",10);
		while($rs=$_G['db']->fetch_array($query)){
			$datas[]=$rs;
		}
		$num=$_G['db']->result("SELECT count(id) FROM".table('car_pinggu')." a WHERE 1 $where ");
		$page=pager($num,10);
		include admintemplate('car/pinggu');
	}
	function recommend(){
		global $_G;
		if( !ican('recommendcars') )msg('没有权限');
		$id=getGP('id','G','int');
		$ids=getGP('id','P','array');
		
		if($id<1  && empty($ids))msg('参数错误');
		
		if( $id )$_G['db']->update('car_cars',array('isrecommend'=>1), array('id'=>$id));
		if(!empty($ids))$_G['db']->query('UPDATE '.table('car_cars').' SET isrecommend=1 WHERE id IN('.implode(',',$ids).")");
		msg('推荐成功');
	}
	function unrecommend(){
		global $_G;
		if( !ican('recommendcars') )msg('没有权限');
		$id=getGP('id','G','int');
		$ids=getGP('id','P','array');
		
		if($id<1  && empty($ids))msg('参数错误');
		
		if( $id )$_G['db']->update('car_cars',array('isrecommend'=>'0'), array('id'=>$id));
		if(!empty($ids))$_G['db']->query('UPDATE '.table('car_cars').' SET isrecommend=0  WHERE id IN('.implode(',',$ids).")");
		msg('取消推荐成功');
	}
	function delete(){
		global $_G;
		if( !ican('deletecars') )msg('没有权限');
		$id=getGP('id','G','int');
		$ids=getGP('id','P','array');
		
		if($id<1  && empty($ids))msg('参数错误');
		
		if( $id )$_G['db']->delete('car_cars',array('id'=>$id));
		if(!empty($ids))$_G['db']->query('DELETE FROM'.table('car_cars').'WHERE id IN('.implode(',',$ids).")");
		msg('删除成功');
	}
	function deleteqiugou(){
		global $_G;
		if( !ican('deleteqiugou') )msg('没有权限');
		$id=getGP('id','G','int');
		$ids=getGP('id','P','array');
		
		if($id<1 && empty($ids))msg('参数错误');
		
		if( $id )$_G['db']->delete('car_qiugou',array('id'=>$id));
		if(!empty($ids))$_G['db']->query('DELETE FROM'.table('car_qiugou').'WHERE id IN('.implode(',',$ids).")");
		msg('删除成功');
	}
	function deletepinggu(){
		global $_G;
		if( !ican('deletepinggu') )msg('没有权限');
		$id=getGP('id','G','int');
		$ids=getGP('id','P','array');
		
		if($id<1 && empty($ids))msg('参数错误');
		
		if( $id )$_G['db']->delete('car_pinggu',array('id'=>$id));
		if(!empty($ids))$_G['db']->query('DELETE FROM'.table('car_pinggu').'WHERE id IN('.implode(',',$ids).")");
		msg('删除成功');
	}
	function check(){
		global $_G;
		if( !ican('checkcars') )msg('没有权限');
		$id=getGP('id','G','int');
		$ids=getGP('id','P','array');
		
		if($id<1  && empty($ids))msg('参数错误');
		
		if( $id )$_G['db']->update('car_cars',array('status'=>1), array('id'=>$id));
		if(!empty($ids))$_G['db']->query('UPDATE '.table('car_cars').' SET status=1 WHERE id IN('.implode(',',$ids).")");
		msg('操作成功');
	}
	function checkqiugou(){
		global $_G;
		if( !ican('checkqiugou') )msg('没有权限');
		$id=getGP('id','G','int');
		$ids=getGP('id','P','array');
		if($id<1 && empty($ids))msg('参数错误');
		
		if( $id )$_G['db']->update('car_qiugou',array('status'=>1), array('id'=>$id));
		if(!empty($ids))$_G['db']->query('UPDATE '.table('car_qiugou').' SET status=1 WHERE id IN('.implode(',',$ids).")");
		msg('操作成功');
	}
	function checkpinggu(){
		global $_G;
		if( !ican('checkpinggu') )msg('没有权限');
		$id=getGP('id','G','int');
		$ids=getGP('id','P','array');
		if($id<1 && empty($ids))msg('参数错误');
		
		if( $id )$_G['db']->update('car_pinggu',array('status'=>1), array('id'=>$id));
		if(!empty($ids))$_G['db']->query('UPDATE '.table('car_pinggu').' SET status=1 WHERE id IN('.implode(',',$ids).")");
		msg('操作成功');
	}
	function uncheck(){
		global $_G;
		if( !ican('uncheckcars') )msg('没有权限');
		$id=getGP('id','G','int');
		$ids=getGP('id','P','array');
		
		if($id<1 || empty($ids))msg('参数错误');
		
		if( $id )$_G['db']->update('car_cars',array('status'=>0), array('id'=>$id));
		if(!empty($ids))$_G['db']->query('UPDATE '.table('car_cars').' SET status=0 WHERE id IN('.implode(',',$ids).")");
		msg('操作成功');
	}
	function uncheckqiugou(){
		global $_G;
		if( !ican('uncheckqiugou') )msg('没有权限');
		$id=getGP('id','G','int');
		$ids=getGP('id','P','array');
		
		if($id<1 && empty($ids))msg('参数错误');
		
		if( $id )$_G['db']->update('car_qiugou',array('status'=>0), array('id'=>$id));
		if(!empty($ids))$_G['db']->query('UPDATE '.table('car_qiugou').' SET status=0 WHERE id IN('.implode(',',$ids).")");
		msg('操作成功');
	}
	function uncheckpinggu(){
		global $_G;
		if( !ican('uncheckpinggu') )msg('没有权限');
		$id=getGP('id','G','int');
		$ids=getGP('id','P','array');
		
		if($id<1 && empty($ids))msg('参数错误');
		
		if( $id )$_G['db']->update('car_pinggu',array('status'=>0), array('id'=>$id));
		if(!empty($ids))$_G['db']->query('UPDATE '.table('car_pinggu').' SET status=0 WHERE id IN('.implode(',',$ids).")");
		msg('操作成功');
	}
}
?>